package com.example.jdimust.register;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.jdimust.util.ACache;
import com.example.jdimust.R;
import com.example.jdimust.main.ui.Expandfunctions.ExpandfunctionsFragment;
import com.suke.widget.SwitchButton;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import okhttp3.MediaType;

/**
 * Author: MaZongyang
 * Date: 2021/5/23/0023 17:27
 * Description:
 */
public class RegisterActivity extends AppCompatActivity {

    public static Activity instance;
    EditText ed_newuser, ed_newpass, ed_newname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (android.os.Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
        setContentView(R.layout.activity_register);
        instance = this;
        ACache acache = ACache.get(this);//创建ACache组件

        com.suke.widget.SwitchButton switchButton = (com.suke.widget.SwitchButton)
                findViewById(R.id.switch_button);
        com.google.android.flexbox.FlexboxLayout flexboxLayout1 = (com.google.android.flexbox.FlexboxLayout)
                findViewById(R.id.dxk);
        com.google.android.flexbox.FlexboxLayout flexboxLayout = (com.google.android.flexbox.FlexboxLayout)
                findViewById(R.id.fxk);

        EditText ed_olduser = (EditText) findViewById(R.id.olduser);
        ed_olduser.setText(acache.getAsString("acauser111"));
        EditText ed_oldpass = (EditText) findViewById(R.id.oldpass);
        EditText ed_newuser = (EditText) findViewById(R.id.newuser);
        EditText ed_newpass = (EditText) findViewById(R.id.newpass);
//        EditText ed_repass = (EditText) findViewById(R.id.newrepass);
        EditText ed_newname = (EditText) findViewById(R.id.newname);

        RadioGroup nRg1 = findViewById(R.id.rg_1);

        CheckBox checkBox1 = (CheckBox) findViewById(R.id.directOperation);
        CheckBox checkBox2 = (CheckBox) findViewById(R.id.contractOperation);
        CheckBox checkBox3 = (CheckBox) findViewById(R.id.configureRoles);
        CheckBox checkBox4 = (CheckBox) findViewById(R.id.authorizeUserRoles);
        CheckBox checkBox5 = (CheckBox) findViewById(R.id.setConsensus);
        CheckBox checkBox6 = (CheckBox) findViewById(R.id.setCrypto);
        CheckBox checkBox7 = (CheckBox) findViewById(R.id.approveTx);
        CheckBox checkBox8 = (CheckBox) findViewById(R.id.consensusTx);
        CheckBox checkBox9 = (CheckBox) findViewById(R.id.registerParticipant);
        CheckBox checkBox10 = (CheckBox) findViewById(R.id.setUserAttributes);
        CheckBox checkBox11 = (CheckBox) findViewById(R.id.registerUser);
        CheckBox checkBox12 = (CheckBox) findViewById(R.id.registerEventAccount);
        CheckBox checkBox13 = (CheckBox) findViewById(R.id.writeEventAccount);
        CheckBox checkBox14 = (CheckBox) findViewById(R.id.registerDataAccount);
        CheckBox checkBox15 = (CheckBox) findViewById(R.id.writeDataAccount);
        CheckBox checkBox16 = (CheckBox) findViewById(R.id.registerContract);
        CheckBox checkBox17 = (CheckBox) findViewById(R.id.upgradeContract);
        Button bt_register = (Button) findViewById(R.id.bt_postnew);
        flexboxLayout1.setVisibility(View.GONE);
        flexboxLayout.setVisibility(View.GONE);

        switchButton.setChecked(true);
        switchButton.isChecked();     //状态
        switchButton.toggle(false);//动画
        switchButton.setShadowEffect(true);//阴影效果
        switchButton.setEnabled(true);//按钮
        switchButton.setEnableEffect(true);//切换动画
        switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(SwitchButton view, boolean isChecked) {
                //TODO do your job
                if (isChecked) {
                    flexboxLayout1.setVisibility(View.VISIBLE);
//                    flexboxLayout.setVisibility(View.VISIBLE);
                } else {
                    flexboxLayout.setVisibility(View.GONE);
                    flexboxLayout1.setVisibility(View.GONE);
                }
            }
        });


        final Integer[] int_directOperation = {0};
        final Integer[] int_contractOperation = {0};
        final Integer[] int_configureRoles = {0};
        final Integer[] int_authorizeUserRoles = {0};
        final Integer[] int_setConsensus = {0};
        final Integer[] int_setCrypto = {0};
        final Integer[] int_approveTx = {0};
        final Integer[] int_consensusTx = {0};
        final Integer[] int_registerParticipant = {0};
        final Integer[] int_setUserAttributes = {0};
        final Integer[] int_registerUser = {0};
        final Integer[] int_registerEventAccount = {0};
        final Integer[] int_writeEventAccount = {0};
        final Integer[] int_registerDataAccount = {0};
        final Integer[] int_writeDataAccount = {0};
        final Integer[] int_registerContract = {0};
        final Integer[] int_upgradeContract = {0};


        nRg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = radioGroup.findViewById(i);
                Log.d("TAG", i + "------" + radioButton.getText().toString() + "-----");
                if (radioButton.getText().toString().equals("自定义") || i == 1) {
                    checkBox1.setChecked(false);
                    int_directOperation[0] = 0;
                    checkBox2.setChecked(false);
                    int_contractOperation[0] = 0;
                    checkBox3.setChecked(false);
                    int_configureRoles[0] = 0;
                    checkBox4.setChecked(false);
                    int_authorizeUserRoles[0] = 0;
                    checkBox5.setChecked(false);
                    int_setConsensus[0] = 0;
                    checkBox6.setChecked(false);
                    int_setCrypto[0] = 0;
                    checkBox7.setChecked(false);
                    int_approveTx[0] = 0;
                    checkBox8.setChecked(false);
                    int_consensusTx[0] = 0;
                    checkBox9.setChecked(false);
                    int_registerParticipant[0] = 0;
                    checkBox10.setChecked(false);
                    int_setUserAttributes[0] = 0;
                    checkBox11.setChecked(false);
                    int_registerUser[0] = 0;
                    checkBox12.setChecked(false);
                    int_registerEventAccount[0] = 0;
                    checkBox13.setChecked(false);
                    int_writeEventAccount[0] = 0;
                    checkBox14.setChecked(false);
                    int_registerDataAccount[0] = 0;
                    checkBox15.setChecked(false);
                    int_writeDataAccount[0] = 0;
                    checkBox16.setChecked(false);
                    int_registerContract[0] = 0;
                    checkBox17.setChecked(false);
                    int_upgradeContract[0] = 0;
                    Log.d("TAG", "事件");
                }
                if (radioButton.getText().toString().equals("事件") || i == 1) {
                    checkBox1.setChecked(false);
                    int_directOperation[0] = 0;
                    checkBox2.setChecked(false);
                    int_contractOperation[0] = 0;
                    checkBox3.setChecked(false);
                    int_configureRoles[0] = 0;
                    checkBox4.setChecked(false);
                    int_authorizeUserRoles[0] = 0;
                    checkBox5.setChecked(false);
                    int_setConsensus[0] = 0;
                    checkBox6.setChecked(false);
                    int_setCrypto[0] = 0;
                    checkBox7.setChecked(false);
                    int_approveTx[0] = 0;
                    checkBox8.setChecked(false);
                    int_consensusTx[0] = 0;
                    checkBox9.setChecked(false);
                    int_registerParticipant[0] = 0;
                    checkBox10.setChecked(false);
                    int_setUserAttributes[0] = 0;
                    checkBox11.setChecked(false);
                    int_registerUser[0] = 0;
                    checkBox12.setChecked(false);
                    int_registerEventAccount[0] = 0;
                    checkBox13.setChecked(true);
                    int_writeEventAccount[0] = 1;
                    checkBox14.setChecked(false);
                    int_registerDataAccount[0] = 0;
                    checkBox15.setChecked(true);
                    int_writeEventAccount[0] = 1;
                    checkBox16.setChecked(false);
                    int_registerContract[0] = 0;
                    checkBox17.setChecked(false);
                    int_upgradeContract[0] = 0;
                    Log.d("TAG", "事件");
                }
                if (radioButton.getText().toString().equals("交易") || i == 2) {
                    checkBox1.setChecked(true);
                    int_directOperation[0] = 1;
                    checkBox2.setChecked(true);
                    int_contractOperation[0] = 1;
                    checkBox3.setChecked(false);
                    int_configureRoles[0] = 0;
                    checkBox4.setChecked(false);
                    int_authorizeUserRoles[0] = 0;
                    checkBox5.setChecked(false);
                    int_setConsensus[0] = 0;
                    checkBox6.setChecked(false);
                    int_setCrypto[0] = 0;
                    checkBox7.setChecked(true);
                    int_approveTx[0] = 1;
                    checkBox8.setChecked(true);
                    int_consensusTx[0] = 1;
                    checkBox10.setChecked(false);
                    int_setUserAttributes[0] = 0;
                    checkBox11.setChecked(false);
                    int_registerUser[0] = 0;
                    checkBox12.setChecked(false);
                    int_registerEventAccount[0] = 0;
                    checkBox13.setChecked(false);
                    int_writeEventAccount[0] = 0;
                    checkBox14.setChecked(false);
                    int_registerDataAccount[0] = 0;
                    checkBox15.setChecked(false);
                    int_writeDataAccount[0] = 0;
                    checkBox16.setChecked(false);
                    int_registerContract[0] = 0;
                    checkBox17.setChecked(false);
                    int_upgradeContract[0] = 0;
                }
                if (radioButton.getText().toString().equals("注册") || i == 3) {
                    checkBox1.setChecked(false);
                    int_directOperation[0] = 0;
                    checkBox2.setChecked(false);
                    int_contractOperation[0] = 0;
                    checkBox3.setChecked(false);
                    int_configureRoles[0] = 0;
                    checkBox4.setChecked(false);
                    int_authorizeUserRoles[0] = 0;
                    checkBox5.setChecked(false);
                    int_setConsensus[0] = 0;
                    checkBox6.setChecked(false);
                    int_setCrypto[0] = 0;
                    checkBox7.setChecked(false);
                    int_approveTx[0] = 0;
                    checkBox8.setChecked(false);
                    int_consensusTx[0] = 0;
                    checkBox9.setChecked(true);
                    int_registerParticipant[0] = 1;
                    checkBox10.setChecked(false);
                    checkBox11.setChecked(true);
                    int_registerUser[0] = 1;
                    checkBox12.setChecked(true);
                    int_registerEventAccount[0] = 1;
                    checkBox13.setChecked(false);
                    int_writeEventAccount[0] = 0;
                    checkBox14.setChecked(true);
                    int_registerDataAccount[0] = 1;
                    checkBox15.setChecked(false);
                    int_writeDataAccount[0] = 0;
                    checkBox16.setChecked(true);
                    int_registerContract[0] = 1;
                    checkBox17.setChecked(false);
                    int_upgradeContract[0] = 0;
                }
                if (radioButton.getText().toString().equals("配置") || i == 4) {
                    checkBox1.setChecked(false);
                    int_directOperation[0] = 0;
                    checkBox2.setChecked(false);
                    int_contractOperation[0] = 0;
                    checkBox3.setChecked(true);
                    int_configureRoles[0] = 1;
                    checkBox4.setChecked(true);
                    int_authorizeUserRoles[0] = 1;
                    checkBox5.setChecked(true);
                    int_setConsensus[0] = 1;
                    checkBox6.setChecked(true);
                    int_setCrypto[0] = 1;
                    checkBox7.setChecked(false);
                    int_approveTx[0] = 0;
                    checkBox8.setChecked(false);
                    int_consensusTx[0] = 0;
                    checkBox9.setChecked(false);
                    int_registerParticipant[0] = 0;
                    checkBox10.setChecked(true);
                    int_setUserAttributes[0] = 1;
                    checkBox11.setChecked(false);
                    int_registerUser[0] = 0;
                    checkBox12.setChecked(false);
                    int_registerEventAccount[0] = 0;
                    checkBox13.setChecked(false);
                    int_writeEventAccount[0] = 0;
                    checkBox14.setChecked(false);
                    int_registerDataAccount[0] = 0;
                    checkBox15.setChecked(true);
                    int_writeDataAccount[0] = 1;
                    checkBox16.setChecked(false);
                    int_registerContract[0] = 0;
                    checkBox17.setChecked(false);
                    int_upgradeContract[0] = 0;
                }
                flexboxLayout.setVisibility(View.VISIBLE);
//                Toast.makeText(RegisterActivity.this, radioButton.getText(), Toast.LENGTH_SHORT).show();
            }
        });





        checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_directOperation[0] = 1;
                    Log.i("tag", checkBox1.getText().toString());
                    Log.i("TAG", String.valueOf(int_directOperation[0]));
                }

            }
        });
        checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_contractOperation[0] = 1;
                    Log.i("tag", checkBox2.getText().toString());
                }

            }
        });
        checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_configureRoles[0] = 1;
                    Log.i("tag", checkBox3.getText().toString());
                }

            }
        });
        checkBox4.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_authorizeUserRoles[0] = 1;
                    Log.i("tag", checkBox4.getText().toString());
                }

            }
        });
        checkBox5.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_setConsensus[0] = 1;
                    Log.i("tag", checkBox5.getText().toString());
                }

            }
        });
        checkBox6.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_setCrypto[0] = 1;
                    Log.i("tag", checkBox6.getText().toString());
                }

            }
        });
        checkBox7.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_approveTx[0] = 1;
                    Log.i("tag", checkBox7.getText().toString());
                }

            }
        });
        checkBox8.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_consensusTx[0] = 1;
                    Log.i("tag", checkBox8.getText().toString());
                }

            }
        });
        checkBox9.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_registerParticipant[0] = 1;
                    Log.i("tag", checkBox9.getText().toString());
                }

            }
        });
        checkBox10.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_setUserAttributes[0] = 1;
                    Log.i("tag", checkBox10.getText().toString());
                }

            }
        });
        checkBox11.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_registerUser[0] = 1;
                    Log.i("tag", checkBox11.getText().toString());
                }

            }
        });
        checkBox12.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_registerEventAccount[0] = 1;
                    Log.i("tag", checkBox12.getText().toString());
                }

            }
        });
        checkBox13.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_writeEventAccount[0] = 1;
                    Log.i("tag", checkBox13.getText().toString());
                }

            }
        });
        checkBox14.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_registerDataAccount[0] = 1;
                    Log.i("tag", checkBox14.getText().toString());
                }

            }
        });
        checkBox15.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_writeDataAccount[0] = 1;
                    Log.i("tag", checkBox15.getText().toString());
                }

            }
        });
        checkBox16.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_registerContract[0] = 1;
                    Log.i("tag", checkBox16.getText().toString());
                }

            }
        });
        checkBox17.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // arg1代表是否选中
                Log.i("tag", arg1 + "");
                if (arg1) {
                    int_upgradeContract[0] = 1;
                    Log.i("tag", checkBox17.getText().toString());
                }

            }
        });



        bt_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                    String tojson = "{\n" +
                            "\"oldUser\": \"" + ed_olduser.getText().toString() + "\",\n" +
                            "\"oldPass\": \"" + ed_oldpass.getText().toString() + "\",\n" +
                            "\"user\": \"" + ed_newuser.getText().toString() + "\",\n" +
                            "\"pass\": \"" + ed_newpass.getText().toString() + "\",\n" +
                            "\"name\": \"" + ed_newname.getText().toString() + "\",\n" +
                            "\"directOperation\": " + int_directOperation[0] + ",\n" +
                            "\"contractOperation\": " + int_contractOperation[0] + ",\n" +
                            "\"configureRoles\": " + int_configureRoles[0] + ",\n" +
                            "\"authorizeUserRoles\": " + int_authorizeUserRoles[0] + ",\n" +
                            "\"setConsensus\": " + int_setConsensus[0] + ",\n" +
                            "\"setCrypto\": " + int_setCrypto[0] + ",\n" +
                            "\"approveTx\": " + int_approveTx[0] + ",\n" +
                            "\"consensusTx\": " + int_consensusTx[0] + ",\n" +
                            "\"registerParticipant\": " + int_registerParticipant[0] + ",\n" +
                            "\"setUserAttributes\": " + int_setUserAttributes[0] + ",\n" +
                            "\"registerUser\": " + int_registerUser[0] + ",\n" +
                            "\"registerEventAccount\": " + int_registerEventAccount[0] + ",\n" +
                            "\"writeEventAccount\": " + int_writeEventAccount[0] + ",\n" +
                            "\"registerDataAccount\": " + int_registerDataAccount[0] + ",\n" +
                            "\"writeDataAccount\": " + int_writeDataAccount[0] + ",\n" +
                            "\"registerContract\": " + int_registerContract[0] + ",\n" +
                            "\"upgradeContract\": " + int_upgradeContract[0] + "\n" +
                            "}";
                    MediaType header = MediaType.parse("application/json; charset=utf-8");
                    System.out.println("--------------\n" + tojson + "\n-----------------");
                    String aregetjson = null;
                    String url = "https://hzy.graduationproject.xyz/Register";
                    MediaType toheader = MediaType.parse("application/json;charset=utf-8");
//            post方法
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost post = new HttpPost(url);
                    StringEntity postingString = null;// json传递
                    try {
                        postingString = new StringEntity(tojson);
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                    post.setEntity(postingString);
                    post.setHeader("Content-type", "application/json");
                    HttpResponse response = null;
                    try {
                        response = httpClient.execute(post);
                        String content = EntityUtils.toString(response.getEntity(), "UTF-8");
                        JSONObject getjson = new JSONObject(content);
                        Boolean flag = getjson.getBoolean("flag");
                        String message = getjson.getString("message");
                        if (flag) {
                            showdialog(message + "\n登录账号: " + ed_newuser.getText().toString() + "\n登录密码:" + ed_newpass.getText().toString() + "\n请牢记！！！");
                        }
                        if (!flag) {
                            showPopup("警告！", message, "返回检查");
                        }
                    } catch (IOException | JSONException e) {
                        e.printStackTrace();
                    }


            }
        });
    }

    private void showdialog(String remes) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
        builder.setMessage(remes);
        builder.setTitle("提示");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(RegisterActivity.this, ExpandfunctionsFragment.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面
                startActivity(intent);
                dialog.dismiss();
                finish();
            }
        });
        builder.setNegativeButton("继续注册", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });
        builder.show();
    }

    public void showPopup(String show_title, String show_message, String show_button) {
        new AlertDialog.Builder(this)
                .setTitle(show_title)
                .setMessage(show_message + "\n请检查输入信息的正确性。")
                .setPositiveButton(show_button, null)
                .show();
    }


}